import 'package:flutter/material.dart';
import 'package:flutter_study/flutter/_07%E9%A1%B5%E9%9D%A2%E6%A1%86%E6%9E%B6/_01BottomNavigationBar.dart';

import '../pages/Product.dart';
import '../pages/Search.dart';

//配置全局路由映射
final routes = {
  '/': (context) => Tabs(), //根路由
  '/search': (context) => SearchPage(), //搜索界面
  //配置带参数的路由
  '/product': (context, {arguments}) => ProductPage(arguments: arguments),
};
//配置路由传值
RouteFactory onGenerateRoute = (RouteSettings settings) {
  // 统一处理
  final String name = settings.name;
  print('name=$name');
  final Function pageContentBuilder = routes[name];
  if (pageContentBuilder != null) {
    if (settings.arguments != null) {
      final Route route = MaterialPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
      return route;
    } else {
      final Route route =
          MaterialPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    }
  }
  return null;
};
